package com.pms.actions;

import java.util.Hashtable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.pms.businesslogic.UserBusinessLogic;
import com.pms.platform.dto.User;
import com.pms.utils.Converter;
import com.pms.utils.ValueObject;

public class EditProfileAction extends FillComboAction {
	public void execute(HttpServletRequest request, HttpServletResponse response) {


		Hashtable error = (Hashtable) request.getAttribute("error");
		HttpSession session =request.getSession();
		if(error!=null && error.size() > 0){
			return;
		}
		try{

			ValueObject inValObj=Converter.convertToValueObject(request);
			String nextPageToken="success";
			User user=(User)request.getSession().getAttribute("user");
			inValObj.put("user", user);

			UserBusinessLogic userBL= new UserBusinessLogic();

			ValueObject outValObj=userBL.editProfile(inValObj);

			outValObj.transferToRequest(request);

			if(outValObj!=null&&outValObj.get("error")!=null){
				error.put("error", outValObj.get("error").toString());
				request.setAttribute("error", error);
				nextPageToken="failure";
			}else{
				User updatedUser=(User)outValObj.get("updatedUser");
				session.setAttribute("user", updatedUser);
			}

			super.execute(request, response);

			request.setAttribute("nextPageToken", nextPageToken);


		}catch (Exception e) {
			e.printStackTrace();
		}

	}
}
